
import 'package:fbroadcast/fbroadcast.dart';
import 'package:flutter/cupertino.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../ChatPage.dart';
import '../List_component/ListComponentPage.dart';
import '../key_board_component/KeyBoardComponentPage.dart';

// 获取id
Future<Object?> obtainValueByKey(String key) async {
  SharedPreferences? prefs = await SharedPreferences.getInstance();
  return await prefs?.get(key);
}

dynamic selectAction(int action, dynamic data,GlobalKey<ListComponentPageState> globalListComponentPageStateKey,GlobalKey<KeyBoardComponentPageState> keyBoardComponentPageStateKey) {
  switch (action) {
    // case 2013:
    //   GlobalKey<ChatPageState> chatPageState = GlobalKey();
    //   chatPageState.currentState?.onPlayerInfo(data);
    //   return null;
    // case 2002:
    //   GlobalKey<ChatPageState> chatPageState = GlobalKey();
    //   chatPageState.currentState?.onServicerInfoFields(data);
    //   return null;
    case 2003:
      if(globalListComponentPageStateKey!=null){
        globalListComponentPageStateKey.currentState?.onShow(data);
      }
      return null;
    case 1010:
      if(keyBoardComponentPageStateKey!=null){
        keyBoardComponentPageStateKey.currentState?.onDontTalk(data);
      }
      return null;
    // case 2005:
    //   GlobalKey<ChatPageState> chatPageState = GlobalKey();
    //   chatPageState.currentState?.chatUserInfo(data);
    //   return null;
    case 2009:
      if(keyBoardComponentPageStateKey!=null){
        keyBoardComponentPageStateKey.currentState?.onEnterStatus(data);
      }
      return null;
    case 2008:
      if(globalListComponentPageStateKey!=null){
        globalListComponentPageStateKey.currentState?.onGetHistory(data);
      }
      return null;
    // case 2012:
    //   GlobalKey<ChatPageState> chatPageState = GlobalKey();
    //   chatPageState.currentState?.onTyping();
    //   return null;
    case 2010:
      if(globalListComponentPageStateKey!=null){
        globalListComponentPageStateKey.currentState?.onWait(data);
      }
      return null;
    case 2000:
      if(globalListComponentPageStateKey!=null){
        globalListComponentPageStateKey.currentState?.onRefuse(data);
      }
      return null;
    case 2006:
      if(globalListComponentPageStateKey!=null){
        globalListComponentPageStateKey.currentState?.onMsgRead();
      }
      return null;
    // case 2004:
    //   GlobalKey<ChatPageState> chatPageState = GlobalKey();
    //   chatPageState.currentState?.onGetVoice(data);
    //   return null;
    // case 2018:
    //   GlobalKey<ChatPageState> chatPageState = GlobalKey();
    //   chatPageState.currentState?.aswer(data);
    //   return null;
    default:
  }
  return null;
}
